/*

skilltype 技能类型  attack--输出   buff-增益
single 单体群体   true--指向   false--非指向
target 友军敌军   army--敌军   friend--友军   self--自身
cut    消耗     
damage 威力
per    命中
distance 范围 （默认为1即单体 每+1范围扩大一圈）
ismagic 法术物理  true--法术  false--物理
ftype  五行  金木水火土
ani    动画
des    描述

//恢复
selfeg   恢复自身能量
targeteg 恢复目标能量
bmg      恢复基础魔法

bhp      恢复基础血量
php      恢复自身比例血量

//状态
status     目标状态
selfstatus 自身状态

//条件
xw         修为限制
*/

//变身系
/*
例:
"变鸡术":{qua:'B',img:'变化',skilltype:'biansen',single:false,target:"self",cut:0,ani:"biansen",animals:'鸡',
            des:"[消耗:0灯][变身成鸡]",xw:{bh:50}}
*/

//召唤系 （特殊召唤:分身）
/*
例：
"叫了个鸡":{qua:'B',img:'召唤',skilltype:'fenshen',single:false,target:"self",cut:0,ani:"biansen",nmb:1,npc:'愤怒的小鸡',
                des:"[特殊][消耗:0灯][在自身周围随机位置召唤一个愤怒的小鸡协助战斗]",xw:{yus:1},ejob:['方士']},
"分身":{qua:'A',img:'召唤',skilltype:'fenshen',single:false,target:"self",cut:2,ani:"biansen",nmb:1,npc:'self',
            des:"[特殊][消耗:2灯][在自身周围随机位置召唤1个自身复制]",xw:{wux:200,bh:200},ejob:['战士','首领']},       
*/

//闪击系
/*
例：
"闪击":{qua:'B',img:'妖',skilltype:'moveAttack',single:true,target:"army",cut:1,ani:"cs",damage:100,ismagic:false,per:0.7,
            des:"[物][威力:100][命中系数0.7][消耗:1灯][传送到敌人身边进行一次攻击]",xw:{kj:50,yaos:50}},
*/

//劝降系 单/群
/*
例：
"劝说":{qua:'A',img:'辩才',skilltype:'getRole',single:true,target:"army",cut:1,ismagic:false,per:0.3,ani:"zao",
            des:"[特殊][单][命中系数0.3][消耗:1灯][消耗等同于目标血量的金钱令目标改变阵营(对BOSS无效)]",xw:{bc:300}},
"登高一呼":{qua:'SS',img:'辩才',skilltype:'getRole',single:false,target:"army",cut:3,ismagic:false,per:0.3,ani:"zao",distance:3,
            des:"[特殊][群][范围2][命中系数0.3][消耗:3灯][消耗等同于目标血量的金钱令自身范围2格内的目标改变阵营(对BOSS无效)]",xw:{bc:800}},        
*/

//自爆系  
/*
例：
"自爆":{qua:'A',img:'医术',skilltype:'zibao',single:false,target:"army",
       cut:0,damage:0,ismagic:true,per:0.5,ani:"zibao_dan",distance:3,
        des:"[特殊][群][威力--][命中系数0.5][消耗:0灯][自身生命降为0,对自身范围2格内的全部敌军造成失去生命数值的伤害]",
        xw:{ys:200,ny:200},ejob:['医师']},
        
*/

//移动系
/*
例：
"腾云术":{qua:'A',img:'空间',skilltype:'move',single:false,cut:3,ani:"cs",distance:3,
        des:"[空间][消耗:3灯][将自身随机传送到2格内的一个位置(概率优先传送离出口最近的位置,此概率受技能命中影响)]",
        xw:{kj:200,xs:200}},
*/

//暗器系
/*
"流星":{qua:'B',img:'暗器',skilltype:'anqi',single:true,target:"army",cut:0,damage:0,
        ismagic:true,per:0.8,ani:"jin_dan",distance:2,
        des:"[特殊][群][威力??][命中系数??][消耗:0灯][使用仓库内第一个未上锁的暗器攻击范围1格内的全部敌军]",xw:{aq:1}},
*/

//输出系 包含 物理/法术  单/群   指向/非指向
/*
例：
"猛击":{qua:'D',img:'枪棒',skilltype:'attack',single:true,target:"army",
               cut:2,damage:200,ismagic:true,per:0.9,ani:"jin_dan",
               des:"[法][单][金][威力200][命中系数0.9][消耗:2灯][攻击目标敌军]",
               xw:{qiang:100},ejob:['战士']},
"横扫":{qua:'D',img:'枪棒',skilltype:'attack',single:false,target:"army",
        cut:4,damage:100,ismagic:true,per:0.9,ani:"jin_dan",distance:1,
        des:"[物][群][威力100][命中系数0.9][消耗:4灯][攻击自身一格内敌军]",
        xw:{qiang:200},ejob:['战士']},
"白虎傲啸":{qua:'SS',img:'经略',skilltype:'attack',single:true,target:"army",
                cut:8,damage:150,ismagic:true,per:0.9,ani:"jin_dan",ftype:'金',distance:1,
                des:"[法][单][金][威力150][命中系数0.9][消耗:8灯][攻击目标一格内敌军]",
                xw:{jin:999,xs:999},ejob:['法师']},
*/

//buff系  包含 治疗/附加buff  单/群   指向/非指向
/*
例： 
"银仙":{qua:'B',img:'医术',skilltype:'buff',single:true,target:"friend",cut:1,ani:"xue_dan",php:30,
        des:"[疗][消耗:1灯][我方单体回复30%自身血量上限的血量]",xw:{ys:1},ejob:['医师']},	
"金仙":{qua:'B',img:'医术',skilltype:'buff',single:true,target:"friend",cut:2,ani:"xue_dan",php:15,distance:2,
        des:"[疗][消耗:2灯][范围1格内友军回复15%自身血量上限的血量]",xw:{ys:50,xs:50},ejob:['医师']},   
*/

window._SKILLTYPE={
        "buff":"状态",
        "biansen":"变身",
        "anqi":"暗器",
        "fenshen":"召唤",
        "attack":"输出",
        "moveAttack":"闪击",
        "getRole":"劝降",
        "zibao":"自爆",
        "moveRole":"移动",
        "move":"传送"
};


window._SKILL = {}


window._SKILLHEPLER={

        _randomMap:null,

        dropMap:null,

        //判定技能是否专属
        isZhuanshu:function(skillname){

                return !_SKILLHEPLER.isSkillCanDrop(skillname);

        },


        isSkillCanDrop:function(skillname){
                return  (_SKILL[skillname]&&!_SKILL[skillname].noshop)
                        ||(_SKILLBD[skillname]&&!_SKILLBD[skillname].noshop);
        },


        getSkillOfDrop:function(boss){

                if(_NPC[boss]){
                        return _NPC[boss].skill;
                }
                
                return null;
        },

        getXWofSkillDes:function(skill){

                if(!_SKILL[skill]
                ||!_SKILL[skill].xw
                ){
                        return "";
                }

               

                return XWH.getStrOfXwObj(_SKILL[skill].xw);

        },

        testSkillAni:function(){
                for(var key in _SKILL){
                        if(_SKILL[key].ani&&!_GRM.skillAni[_SKILL[key].ani]){
                                console.log('特效缺失:',key,_SKILL[key].ani);
                        }

                        if(_SKILL[key].status&&!_STATUSCONFCHESS[_SKILL[key].status]){
                                console.log('状态异常:',key,_SKILL[key].status);
                        }

                        if(_SKILL[key].selfstatus&&!_STATUSCONFCHESS[_SKILL[key].selfstatus]){
                                console.log('状态异常:',key,_SKILL[key].selfstatus);
                        }
                }
        },

        testAllJobRandomSkill:function(){

                for(var key in _JOB){
                        for(var ftype in _CS.ftype){
                                console.log(key,ftype,_SKILLHEPLER.getRandomSkillForJob(key,ftype));
                        }
                }

        },

        getRandomSkillForJob:function(job,ftype){
                _SKILLHEPLER.initSkillMapForRandom();
                var jobConf = _JOB[job];
                var jobskilltypeArr = jobConf.skillType;
                var skilltype = null;
                if(jobskilltypeArr&&jobskilltypeArr.length>0){
                        skilltype=_CU.randomObj(jobskilltypeArr);
                }

                if(skilltype&&_SKILLHEPLER._randomMap[skilltype]){

                        if(_SKILLHEPLER._randomMap[skilltype][ftype]){
                                return _CU.randomObj(_SKILLHEPLER._randomMap[skilltype][ftype]);
                        }else{
                                return _CU.randomObj(_SKILLHEPLER._randomMap[skilltype]['无']);
                        }

                }
                
        },

        initSkillMapForRandom:function(){

                if(!_SKILLHEPLER._randomMap){
                        _SKILLHEPLER._randomMap={};
                        for(var key in _SKILL){
                                if(_SKILLHEPLER.skillCanRandom(key)){
                                        var skillConf = _SKILL[key];
                                        var skillftype = skillConf.ftype?skillConf.ftype:'无';
                                        var skilltype = skillConf.type?skillConf.type:'通用';
                                        if(!_SKILLHEPLER._randomMap[skilltype]){
                                                _SKILLHEPLER._randomMap[skilltype]={};
                                        }
                                        if(!_SKILLHEPLER._randomMap[skilltype][skillftype]){
                                                _SKILLHEPLER._randomMap[skilltype][skillftype]=[];
                                        }
                                        _SKILLHEPLER._randomMap[skilltype][skillftype].push(key);
                                }
                        }
                }

        },

        skillCanRandom:function(skillname){

                var skillConf = _SKILL[skillname]?_SKILL[skillname]:_SKILLBD[skillname];

                if(skillConf){

                        return !skillConf.forbidden
                                &&!skillConf.only
                                &&!skillConf.exc;

                }

                return false;

        },

        wearSelfExc:function(role,skillName){
                var skillConf = _SKILL[skillName]?_SKILL[skillName]:_SKILLBD[skillName];
                if(
                        skillConf
                        &&role
                        &&skillConf.exc == role.name
                ){
                        return true;
                }
                return false;
        },

        getRoleSkillNmb:function(role){

                return 10;

        },

        getCanwearSKill:function(){

                return 999999;
        },

        canWear:function(role,skillName){

                var maxskillnmb = _SKILLHEPLER.getCanwearSKill();
                var skillConf = _SKILL[skillName]?_SKILL[skillName]:_SKILLBD[skillName];

                if(role.skill.length>=maxskillnmb){
                        return {flag:false,msg:"此人最多只能装备"+maxskillnmb+"个技能,请先卸载再装备"}; 
                }

                if(_SKILL[skillName]
                   &&_SKILL[skillName].ejob     
                ){
                        var realjob =_MRDL.getJobOfRole(role);
                        if(!_CU.isContain(_SKILL[skillName].ejob,realjob)){
                                return {flag:false,msg:"不满足职业条件无法装备"}; 
                        }
                }

                if(role.skill&&role.skill.length>0){
                        for(var i=0;i<role.skill.length;i++){
                                if(role.skill[i]==skillName){
                                        return {flag:false,msg:"无法装备同名技能"}; 
                                } 
                        }
                }

                if(!XWH.isXwEnough(skillConf,role)){
                        return {flag:false,msg:"修为不足无法装备"};
                }

                return {flag:true};
        }

}